package com.tiantian.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tiantian.dao.BuyersBankCardRepository;
import com.tiantian.datajpa.service.impl.GenericServiceImpl;
import com.tiantian.domain.Buyersbankcard;
import com.tiantian.domain.BuyersbankcardId;
import com.tiantian.service.BuyersBankCardService;

@Service
@Transactional
public class BuyersBankCardServiceImpl extends GenericServiceImpl<Buyersbankcard, BuyersbankcardId> implements BuyersBankCardService {
	private BuyersBankCardRepository repository;

	@Autowired
	public void setRepository(BuyersBankCardRepository repository) {
		super.setGenericDAO(repository);
		this.repository = repository;
	}

	/**
	 * 获取买手银行卡列表
	 * 
	 * @param params
	 * @param page
	 * @return
	 */
	public List<Map<String, Object>> list(Map<String, String> searchMap) {
		StringBuilder sql = new StringBuilder();
		Map<String, Object> params = new HashMap<String, Object>();
		sql.append("select a.*,b.bankname bname,c.areaname,d.bankname aname from BuyersBankCard a ");
		sql.append(" left join banklist b  on a.bankname=b.bankid");
		sql.append(" left join banklist d  on a.accountbank=d.bankid");
		sql.append(" left join RegionalInformation c  on c.areacode=a.city where 1=1");
		if (searchMap != null) {

			String buyersUserID = searchMap.get("buyersUserID");
			if (StringUtils.isNotBlank(buyersUserID)) {
				sql.append(" and buyersUserID like :buyersUserID ");
				params.put("buyersUserID", '%' + buyersUserID.trim() + '%');
			}
		}
		List<Map<String, Object>> ret = repository.queryHumpListMapBySql(sql.toString(), params);
		return ret;
	}

}
